package com.zznj.xzjc.adapter.index;

import android.text.Html;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zznj.xzjc.R;
import com.zznj.xzjc.net.entity.IndexNewXianSuoBean;
import com.zznj.xzjc.utils.StringUtils;
import com.zznj.xzjc.utils.TimeUtils;

import java.util.List;

/**
 * 描述：添加类的描述
 *
 * @author wx5e48d604c2885118
 * @time 2020/4/7
 */
public class WorkAdapter extends BaseQuickAdapter<IndexNewXianSuoBean, BaseViewHolder> {

    private String searchType;
    public WorkAdapter(int layoutResId, @Nullable List<IndexNewXianSuoBean> data,String leixing) {
        super(layoutResId, data);
        this.searchType = leixing;
    }

    private String key;
    public void setKey(String key){
        this.key = key;
        notifyDataSetChanged();
    }

    @Override
    protected void convert(BaseViewHolder helper, IndexNewXianSuoBean item) {
        if(StringUtils.isEmptyForContent(key)){
            helper.setText(R.id.tv_title, StringUtils.delHtmlTags(item.getIndexTitle_s()));
            helper.setText(R.id.tv_content, StringUtils.delHtmlTags(item.getSummary_cn()));
        }else{
            helper.setText(R.id.tv_title, Html.fromHtml(StringUtils.delHtmlTags(item.getIndexTitle_s()).replace(key,"<span style='color:red;'>"+key+"</span>")));
            helper.setText(R.id.tv_content, Html.fromHtml(StringUtils.delHtmlTags(item.getSummary_cn()).replace(key,"<span style='color:red;'>"+key+"</span>")));
        }
        helper.setText(R.id.tv_date, "发布时间："+TimeUtils.getTime(item.getPublishTime_date(),"yyyy-MM-dd"));
        ImageView tishiLogo = helper.getView(R.id.tishiLogo);
        if("9".equals(item.getDataType_i())){
            tishiLogo.setImageResource(R.mipmap.gyss_work_gzdt);
            helper.setText(R.id.tv_leixing, "工作动态");
        }else if("12".equals(item.getDataType_i())){
            tishiLogo.setImageResource(R.mipmap.gyss_work_cpzh_img);
            helper.setText(R.id.tv_leixing, "产品召回");
        }else if("11".equals(item.getDataType_i())){
            tishiLogo.setImageResource(R.mipmap.gyss_work_zcfb);
            helper.setText(R.id.tv_leixing, "政策发布");
        }else if("10".equals(item.getDataType_i())){
            tishiLogo.setImageResource(R.mipmap.gyss_work_albb_img);
            helper.setText(R.id.tv_leixing, "案例播报");
        }else if("15".equals(item.getDataType_i())){
            tishiLogo.setImageResource(R.mipmap.gyss_work_tzgg_img);
            helper.setText(R.id.tv_leixing, "通知公告");
        }
        View logoLinear = helper.getView(R.id.logoLinear);
        if("NoticeAll".equals(searchType)){
            logoLinear.setVisibility(View.VISIBLE);
        }else{
            logoLinear.setVisibility(View.GONE);
        }
    }
}
